/**
 * CenteredBackgoundBorder.java 
 * 
 * @author Beatrice Bacelli
 * @author Luca Bedogni
 * @author Silvia Righini
 */
package unibo.lsb.graphic;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.image.BufferedImage;

import javax.swing.border.Border;

public class CenteredBackgroundBorder implements Border {

	private final BufferedImage image;

	public CenteredBackgroundBorder(BufferedImage bi) {
		image = bi;
	}

	public void paintBorder(Component c, Graphics g, int x, int y, int width,
			int height) {
		int x0 = x + (width - image.getWidth()) / 2;
		int y0 = y + (height - image.getHeight()) / 2;
		g.drawImage(image, x0, y0, null);
	}

	public Insets getBorderInsets(Component c) {
		return new Insets(0, 0, 0, 0);
	}

	public boolean isBorderOpaque() {
		return true;
	}

	public Dimension getImageDimension() {
		return new Dimension(image.getWidth(), image.getHeight());
	}
}
